package com.sirui.x.learnBoot;

import java.util.Collections;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class MpCodeGenerator {

    private static final String url = "jdbc:mysql://localhost:3306/order_info?useUnicode=true&characterEncoding=utf8&useSSL=false";
    private static final String uname = "root";
    private static final String pwd = "kw@123";

    public static void main(String[] args) {
        String baseDir = System.getProperty("user.dir");
        String author = System.getProperty("user.name");
        FastAutoGenerator.create(url, uname, pwd)
                .globalConfig(builder -> {
                    builder.author(author).fileOverride()
                            .outputDir(baseDir + "/src/main/java/");
                })
                //包配置，com.sirui.cloud.oc
                .packageConfig(builder -> {
                    builder.parent("com.sirui.x").moduleName("learnBoot")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,
                                    baseDir + "/src/main/resources/mapper"));
                })
                //配置表
                .strategyConfig(builder -> {
                    // 不适用addInclude 默认生成全表
                    builder.addInclude("ic_sign_credential").addTablePrefix("ic_")
                    		//实体类builder配置
                            .entityBuilder().convertFileName(entityName -> entityName + "DO")
                            // 服务类builder配置
                            .serviceBuilder().convertServiceFileName(svcName -> svcName + "Service")
                            // mapper的builder配置
                            .mapperBuilder().enableMapperAnnotation()
                            ;
                })
                .templateEngine(new FreemarkerTemplateEngine()).execute();
    }
}
